#ifndef __MCS__RUN_TIME_EXCEPTION__HPP
#define __MCS__RUN_TIME_EXCEPTION__HPP

#include "Exception.hpp"
#include "SourceLocation.hpp"
#include <cassert>

class RunTimeException : public Exception
{
};

class AssertionFailureException : public RunTimeException
{
public:
	AssertionFailureException(char const * file, int line, char const * text)
		: RunTimeException()
		, pos_(file, line), text_(text)
	{}

	SourcePosition position() const { return pos_; }
	String text() const { return text_; }

	virtual std::ostream & stream(std::ostream & str) const
	{
		return str << pos_ << ": Assertion failed: " << text_;
	}
private:
	SourcePosition pos_;
	String text_;
};


#if defined(NDEBUG)
#define MCSC_ASSERT(X) do { if(!(X)) throw AssertionFailureException(__FILE__, __LINE__, #X); } while(0)
#else
#define MCSC_ASSERT(X) assert(X)
#endif //defined(NDEBUG)
	


#endif //__MCS__RUN_TIME_EXCEPTION__HPP
